package com.good.cm.interceptor;

import com.good.cm.exception.NoLoginException;
import com.good.cm.service.UserService;
import com.good.cm.utils.CookieUtil;
import com.good.cm.vo.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class NoLoginInterceptor extends HandlerInterceptorAdapter {

    @Resource
    private UserService userService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //拦截判断是否登录
        String userid= CookieUtil.getCookieUserId(request);
        if (null==userid|| StringUtils.isBlank(userid))
        {
            throw new NoLoginException();
        }
        return  super.preHandle(request,response,handler);
    }

}
